{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# some_file.py\n",
    "import sys\n",
    "# insert at 1, 0 is the script path (or '' in REPL)\n",
    "sys.path.insert(1, '../')\n",
    "from lxrt.SlowFast.slowfast.config.defaults import get_cfg\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from lxrt.SlowFast.slowfast.datasets.tgif_direct import TGIF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = TGIF(cfg, \"train\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "cfg = get_cfg()\n",
    "cfg_file = \"../lxrt/SlowFast/configs/Kinetics/c2/SLOWFAST_8x8_R50.yaml\"\n",
    "cfg.merge_from_file(cfg_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/users/cdwivedi/RL_EXP/IDL/project/tgif-qa/code/dataset/tgif/gifs/tumblr_nqc2mbmU2J1uxhtnwo1_400.gi/*\n",
      "torch.Size([3, 8, 256, 256]) torch.Size([3, 32, 256, 256])\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[tensor([[[[-1.9914, -1.9918, -1.9923,  ..., -1.9882, -1.9883, -1.9884],\n",
       "           [-1.9917, -1.9920, -1.9924,  ..., -1.9884, -1.9885, -1.9886],\n",
       "           [-1.9919, -1.9921, -1.9924,  ..., -1.9886, -1.9888, -1.9889],\n",
       "           ...,\n",
       "           [-1.9930, -1.9930, -1.9930,  ..., -1.9926, -1.9927, -1.9926],\n",
       "           [-1.9932, -1.9933, -1.9934,  ..., -1.9925, -1.9927, -1.9926],\n",
       "           [-1.9935, -1.9936, -1.9937,  ..., -1.9926, -1.9928, -1.9926]],\n",
       " \n",
       "          [[-1.9917, -1.9919, -1.9923,  ..., -1.9883, -1.9883, -1.9882],\n",
       "           [-1.9919, -1.9920, -1.9922,  ..., -1.9887, -1.9886, -1.9886],\n",
       "           [-1.9919, -1.9919, -1.9922,  ..., -1.9889, -1.9890, -1.9890],\n",
       "           ...,\n",
       "           [-1.9938, -1.9936, -1.9935,  ..., -1.9862, -1.9854, -1.9848],\n",
       "           [-1.9945, -1.9942, -1.9941,  ..., -1.9865, -1.9857, -1.9850],\n",
       "           [-1.9946, -1.9944, -1.9942,  ..., -1.9869, -1.9861, -1.9852]],\n",
       " \n",
       "          [[-1.9915, -1.9916, -1.9919,  ..., -1.9882, -1.9882, -1.9882],\n",
       "           [-1.9915, -1.9917, -1.9919,  ..., -1.9885, -1.9886, -1.9886],\n",
       "           [-1.9917, -1.9918, -1.9920,  ..., -1.9887, -1.9888, -1.9888],\n",
       "           ...,\n",
       "           [-1.9875, -1.9879, -1.9885,  ..., -1.9843, -1.9843, -1.9843],\n",
       "           [-1.9869, -1.9877, -1.9887,  ..., -1.9843, -1.9843, -1.9843],\n",
       "           [-1.9863, -1.9875, -1.9890,  ..., -1.9843, -1.9843, -1.9843]],\n",
       " \n",
       "          ...,\n",
       " \n",
       "          [[-1.9918, -1.9919, -1.9920,  ..., -1.9887, -1.9887, -1.9887],\n",
       "           [-1.9918, -1.9919, -1.9920,  ..., -1.9886, -1.9886, -1.9886],\n",
       "           [-1.9918, -1.9919, -1.9920,  ..., -1.9886, -1.9886, -1.9886],\n",
       "           ...,\n",
       "           [-1.9960, -1.9960, -1.9960,  ..., -1.9913, -1.9913, -1.9913],\n",
       "           [-1.9960, -1.9960, -1.9960,  ..., -1.9903, -1.9903, -1.9903],\n",
       "           [-1.9960, -1.9960, -1.9960,  ..., -1.9895, -1.9895, -1.9895]],\n",
       " \n",
       "          [[-1.9918, -1.9919, -1.9920,  ..., -1.9886, -1.9886, -1.9886],\n",
       "           [-1.9918, -1.9919, -1.9920,  ..., -1.9885, -1.9885, -1.9885],\n",
       "           [-1.9918, -1.9919, -1.9920,  ..., -1.9885, -1.9885, -1.9885],\n",
       "           ...,\n",
       "           [-1.9960, -1.9960, -1.9960,  ..., -1.9914, -1.9914, -1.9914],\n",
       "           [-1.9960, -1.9960, -1.9960,  ..., -1.9904, -1.9904, -1.9904],\n",
       "           [-1.9960, -1.9960, -1.9960,  ..., -1.9896, -1.9896, -1.9896]],\n",
       " \n",
       "          [[-1.9918, -1.9919, -1.9920,  ..., -1.9886, -1.9886, -1.9886],\n",
       "           [-1.9918, -1.9919, -1.9920,  ..., -1.9885, -1.9885, -1.9885],\n",
       "           [-1.9918, -1.9919, -1.9920,  ..., -1.9885, -1.9885, -1.9885],\n",
       "           ...,\n",
       "           [-1.9947, -1.9937, -1.9925,  ..., -1.9914, -1.9914, -1.9914],\n",
       "           [-1.9947, -1.9937, -1.9925,  ..., -1.9904, -1.9904, -1.9904],\n",
       "           [-1.9947, -1.9937, -1.9925,  ..., -1.9896, -1.9896, -1.9896]]],\n",
       " \n",
       " \n",
       "         [[[-1.9919, -1.9924, -1.9929,  ..., -1.9889, -1.9889, -1.9889],\n",
       "           [-1.9921, -1.9925, -1.9930,  ..., -1.9894, -1.9895, -1.9895],\n",
       "           [-1.9923, -1.9926, -1.9930,  ..., -1.9898, -1.9899, -1.9899],\n",
       "           ...,\n",
       "           [-1.9945, -1.9945, -1.9946,  ..., -1.9937, -1.9939, -1.9938],\n",
       "           [-1.9949, -1.9949, -1.9950,  ..., -1.9934, -1.9936, -1.9935],\n",
       "           [-1.9950, -1.9951, -1.9952,  ..., -1.9931, -1.9933, -1.9931]],\n",
       " \n",
       "          [[-1.9927, -1.9927, -1.9930,  ..., -1.9889, -1.9889, -1.9889],\n",
       "           [-1.9926, -1.9925, -1.9928,  ..., -1.9894, -1.9894, -1.9894],\n",
       "           [-1.9926, -1.9925, -1.9927,  ..., -1.9898, -1.9898, -1.9898],\n",
       "           ...,\n",
       "           [-1.9944, -1.9945, -1.9946,  ..., -1.9870, -1.9860, -1.9850],\n",
       "           [-1.9953, -1.9953, -1.9953,  ..., -1.9872, -1.9863, -1.9854],\n",
       "           [-1.9956, -1.9956, -1.9956,  ..., -1.9875, -1.9869, -1.9863]],\n",
       " \n",
       "          [[-1.9921, -1.9922, -1.9926,  ..., -1.9890, -1.9890, -1.9889],\n",
       "           [-1.9922, -1.9923, -1.9926,  ..., -1.9894, -1.9894, -1.9894],\n",
       "           [-1.9923, -1.9924, -1.9927,  ..., -1.9898, -1.9898, -1.9898],\n",
       "           ...,\n",
       "           [-1.9880, -1.9883, -1.9890,  ..., -1.9850, -1.9850, -1.9850],\n",
       "           [-1.9874, -1.9882, -1.9893,  ..., -1.9850, -1.9850, -1.9850],\n",
       "           [-1.9870, -1.9881, -1.9896,  ..., -1.9850, -1.9850, -1.9850]],\n",
       " \n",
       "          ...,\n",
       " \n",
       "          [[-1.9928, -1.9928, -1.9929,  ..., -1.9891, -1.9891, -1.9891],\n",
       "           [-1.9928, -1.9928, -1.9929,  ..., -1.9893, -1.9893, -1.9893],\n",
       "           [-1.9928, -1.9928, -1.9929,  ..., -1.9895, -1.9895, -1.9895],\n",
       "           ...,\n",
       "           [-1.9969, -1.9969, -1.9969,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9969, -1.9969, -1.9969,  ..., -1.9915, -1.9915, -1.9915],\n",
       "           [-1.9969, -1.9969, -1.9969,  ..., -1.9907, -1.9907, -1.9907]],\n",
       " \n",
       "          [[-1.9928, -1.9928, -1.9929,  ..., -1.9891, -1.9891, -1.9891],\n",
       "           [-1.9928, -1.9928, -1.9929,  ..., -1.9892, -1.9892, -1.9892],\n",
       "           [-1.9928, -1.9928, -1.9929,  ..., -1.9894, -1.9894, -1.9894],\n",
       "           ...,\n",
       "           [-1.9970, -1.9970, -1.9970,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9970, -1.9970, -1.9970,  ..., -1.9915, -1.9915, -1.9915],\n",
       "           [-1.9970, -1.9970, -1.9970,  ..., -1.9907, -1.9907, -1.9907]],\n",
       " \n",
       "          [[-1.9928, -1.9928, -1.9929,  ..., -1.9890, -1.9890, -1.9890],\n",
       "           [-1.9928, -1.9928, -1.9929,  ..., -1.9891, -1.9891, -1.9891],\n",
       "           [-1.9928, -1.9928, -1.9929,  ..., -1.9893, -1.9893, -1.9893],\n",
       "           ...,\n",
       "           [-1.9953, -1.9943, -1.9931,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9953, -1.9943, -1.9931,  ..., -1.9915, -1.9915, -1.9915],\n",
       "           [-1.9953, -1.9943, -1.9931,  ..., -1.9907, -1.9907, -1.9907]]],\n",
       " \n",
       " \n",
       "         [[[-1.9930, -1.9934, -1.9940,  ..., -1.9897, -1.9898, -1.9900],\n",
       "           [-1.9932, -1.9936, -1.9940,  ..., -1.9903, -1.9905, -1.9905],\n",
       "           [-1.9934, -1.9937, -1.9940,  ..., -1.9909, -1.9910, -1.9911],\n",
       "           ...,\n",
       "           [-1.9954, -1.9954, -1.9954,  ..., -1.9948, -1.9949, -1.9948],\n",
       "           [-1.9957, -1.9958, -1.9959,  ..., -1.9946, -1.9948, -1.9947],\n",
       "           [-1.9960, -1.9961, -1.9962,  ..., -1.9944, -1.9946, -1.9945]],\n",
       " \n",
       "          [[-1.9930, -1.9932, -1.9936,  ..., -1.9898, -1.9898, -1.9899],\n",
       "           [-1.9932, -1.9933, -1.9936,  ..., -1.9904, -1.9905, -1.9905],\n",
       "           [-1.9932, -1.9933, -1.9935,  ..., -1.9910, -1.9911, -1.9911],\n",
       "           ...,\n",
       "           [-1.9952, -1.9953, -1.9954,  ..., -1.9881, -1.9870, -1.9860],\n",
       "           [-1.9961, -1.9961, -1.9961,  ..., -1.9882, -1.9873, -1.9864],\n",
       "           [-1.9965, -1.9965, -1.9964,  ..., -1.9888, -1.9881, -1.9873]],\n",
       " \n",
       "          [[-1.9931, -1.9933, -1.9936,  ..., -1.9898, -1.9898, -1.9897],\n",
       "           [-1.9932, -1.9933, -1.9936,  ..., -1.9904, -1.9904, -1.9904],\n",
       "           [-1.9933, -1.9935, -1.9937,  ..., -1.9909, -1.9910, -1.9910],\n",
       "           ...,\n",
       "           [-1.9885, -1.9888, -1.9895,  ..., -1.9861, -1.9861, -1.9861],\n",
       "           [-1.9880, -1.9888, -1.9899,  ..., -1.9861, -1.9861, -1.9861],\n",
       "           [-1.9876, -1.9888, -1.9902,  ..., -1.9861, -1.9861, -1.9861]],\n",
       " \n",
       "          ...,\n",
       " \n",
       "          [[-1.9936, -1.9937, -1.9938,  ..., -1.9910, -1.9910, -1.9910],\n",
       "           [-1.9936, -1.9937, -1.9938,  ..., -1.9911, -1.9911, -1.9911],\n",
       "           [-1.9936, -1.9937, -1.9938,  ..., -1.9912, -1.9912, -1.9912],\n",
       "           ...,\n",
       "           [-1.9975, -1.9975, -1.9975,  ..., -1.9936, -1.9936, -1.9936],\n",
       "           [-1.9975, -1.9975, -1.9975,  ..., -1.9926, -1.9926, -1.9926],\n",
       "           [-1.9975, -1.9975, -1.9975,  ..., -1.9918, -1.9918, -1.9918]],\n",
       " \n",
       "          [[-1.9936, -1.9937, -1.9938,  ..., -1.9910, -1.9910, -1.9910],\n",
       "           [-1.9936, -1.9937, -1.9938,  ..., -1.9911, -1.9911, -1.9911],\n",
       "           [-1.9936, -1.9937, -1.9938,  ..., -1.9912, -1.9912, -1.9912],\n",
       "           ...,\n",
       "           [-1.9976, -1.9976, -1.9976,  ..., -1.9935, -1.9935, -1.9935],\n",
       "           [-1.9976, -1.9976, -1.9976,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9976, -1.9976, -1.9976,  ..., -1.9917, -1.9917, -1.9917]],\n",
       " \n",
       "          [[-1.9936, -1.9937, -1.9938,  ..., -1.9908, -1.9908, -1.9908],\n",
       "           [-1.9936, -1.9937, -1.9938,  ..., -1.9909, -1.9909, -1.9909],\n",
       "           [-1.9936, -1.9937, -1.9938,  ..., -1.9910, -1.9910, -1.9910],\n",
       "           ...,\n",
       "           [-1.9956, -1.9947, -1.9934,  ..., -1.9935, -1.9935, -1.9935],\n",
       "           [-1.9956, -1.9947, -1.9934,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9956, -1.9947, -1.9934,  ..., -1.9917, -1.9917, -1.9917]]]]),\n",
       " tensor([[[[-1.9914, -1.9918, -1.9923,  ..., -1.9882, -1.9883, -1.9884],\n",
       "           [-1.9917, -1.9920, -1.9924,  ..., -1.9884, -1.9885, -1.9886],\n",
       "           [-1.9919, -1.9921, -1.9924,  ..., -1.9886, -1.9888, -1.9889],\n",
       "           ...,\n",
       "           [-1.9930, -1.9930, -1.9930,  ..., -1.9926, -1.9927, -1.9926],\n",
       "           [-1.9932, -1.9933, -1.9934,  ..., -1.9925, -1.9927, -1.9926],\n",
       "           [-1.9935, -1.9936, -1.9937,  ..., -1.9926, -1.9928, -1.9926]],\n",
       " \n",
       "          [[-1.9914, -1.9918, -1.9923,  ..., -1.9882, -1.9883, -1.9884],\n",
       "           [-1.9917, -1.9920, -1.9924,  ..., -1.9884, -1.9885, -1.9886],\n",
       "           [-1.9919, -1.9921, -1.9924,  ..., -1.9886, -1.9888, -1.9889],\n",
       "           ...,\n",
       "           [-1.9930, -1.9930, -1.9930,  ..., -1.9926, -1.9927, -1.9926],\n",
       "           [-1.9932, -1.9933, -1.9934,  ..., -1.9925, -1.9927, -1.9926],\n",
       "           [-1.9935, -1.9936, -1.9937,  ..., -1.9926, -1.9928, -1.9926]],\n",
       " \n",
       "          [[-1.9917, -1.9919, -1.9923,  ..., -1.9884, -1.9885, -1.9886],\n",
       "           [-1.9919, -1.9920, -1.9924,  ..., -1.9885, -1.9886, -1.9888],\n",
       "           [-1.9919, -1.9920, -1.9923,  ..., -1.9886, -1.9889, -1.9891],\n",
       "           ...,\n",
       "           [-1.9937, -1.9936, -1.9935,  ..., -1.9847, -1.9847, -1.9846],\n",
       "           [-1.9940, -1.9939, -1.9939,  ..., -1.9845, -1.9845, -1.9845],\n",
       "           [-1.9939, -1.9940, -1.9941,  ..., -1.9847, -1.9845, -1.9845]],\n",
       " \n",
       "          ...,\n",
       " \n",
       "          [[-1.9919, -1.9920, -1.9921,  ..., -1.9886, -1.9886, -1.9886],\n",
       "           [-1.9919, -1.9920, -1.9921,  ..., -1.9885, -1.9885, -1.9885],\n",
       "           [-1.9919, -1.9920, -1.9921,  ..., -1.9885, -1.9885, -1.9885],\n",
       "           ...,\n",
       "           [-1.9942, -1.9937, -1.9931,  ..., -1.9914, -1.9914, -1.9914],\n",
       "           [-1.9942, -1.9937, -1.9931,  ..., -1.9904, -1.9904, -1.9904],\n",
       "           [-1.9942, -1.9937, -1.9931,  ..., -1.9896, -1.9896, -1.9896]],\n",
       " \n",
       "          [[-1.9918, -1.9919, -1.9920,  ..., -1.9886, -1.9886, -1.9886],\n",
       "           [-1.9918, -1.9919, -1.9920,  ..., -1.9885, -1.9885, -1.9885],\n",
       "           [-1.9918, -1.9919, -1.9920,  ..., -1.9885, -1.9885, -1.9885],\n",
       "           ...,\n",
       "           [-1.9947, -1.9937, -1.9925,  ..., -1.9914, -1.9914, -1.9914],\n",
       "           [-1.9947, -1.9937, -1.9925,  ..., -1.9904, -1.9904, -1.9904],\n",
       "           [-1.9947, -1.9937, -1.9925,  ..., -1.9896, -1.9896, -1.9896]],\n",
       " \n",
       "          [[-1.9918, -1.9919, -1.9920,  ..., -1.9886, -1.9886, -1.9886],\n",
       "           [-1.9918, -1.9919, -1.9920,  ..., -1.9885, -1.9885, -1.9885],\n",
       "           [-1.9918, -1.9919, -1.9920,  ..., -1.9885, -1.9885, -1.9885],\n",
       "           ...,\n",
       "           [-1.9947, -1.9937, -1.9925,  ..., -1.9914, -1.9914, -1.9914],\n",
       "           [-1.9947, -1.9937, -1.9925,  ..., -1.9904, -1.9904, -1.9904],\n",
       "           [-1.9947, -1.9937, -1.9925,  ..., -1.9896, -1.9896, -1.9896]]],\n",
       " \n",
       " \n",
       "         [[[-1.9919, -1.9924, -1.9929,  ..., -1.9889, -1.9889, -1.9889],\n",
       "           [-1.9921, -1.9925, -1.9930,  ..., -1.9894, -1.9895, -1.9895],\n",
       "           [-1.9923, -1.9926, -1.9930,  ..., -1.9898, -1.9899, -1.9899],\n",
       "           ...,\n",
       "           [-1.9945, -1.9945, -1.9946,  ..., -1.9937, -1.9939, -1.9938],\n",
       "           [-1.9949, -1.9949, -1.9950,  ..., -1.9934, -1.9936, -1.9935],\n",
       "           [-1.9950, -1.9951, -1.9952,  ..., -1.9931, -1.9933, -1.9931]],\n",
       " \n",
       "          [[-1.9919, -1.9924, -1.9929,  ..., -1.9889, -1.9889, -1.9889],\n",
       "           [-1.9921, -1.9925, -1.9930,  ..., -1.9894, -1.9895, -1.9895],\n",
       "           [-1.9923, -1.9926, -1.9930,  ..., -1.9898, -1.9899, -1.9899],\n",
       "           ...,\n",
       "           [-1.9945, -1.9945, -1.9946,  ..., -1.9937, -1.9939, -1.9938],\n",
       "           [-1.9949, -1.9949, -1.9950,  ..., -1.9934, -1.9936, -1.9935],\n",
       "           [-1.9950, -1.9951, -1.9952,  ..., -1.9931, -1.9933, -1.9931]],\n",
       " \n",
       "          [[-1.9922, -1.9925, -1.9929,  ..., -1.9888, -1.9887, -1.9888],\n",
       "           [-1.9924, -1.9926, -1.9930,  ..., -1.9893, -1.9894, -1.9894],\n",
       "           [-1.9925, -1.9925, -1.9929,  ..., -1.9896, -1.9898, -1.9898],\n",
       "           ...,\n",
       "           [-1.9945, -1.9945, -1.9946,  ..., -1.9857, -1.9859, -1.9860],\n",
       "           [-1.9948, -1.9949, -1.9951,  ..., -1.9854, -1.9856, -1.9857],\n",
       "           [-1.9951, -1.9951, -1.9953,  ..., -1.9854, -1.9855, -1.9854]],\n",
       " \n",
       "          ...,\n",
       " \n",
       "          [[-1.9928, -1.9929, -1.9930,  ..., -1.9890, -1.9890, -1.9890],\n",
       "           [-1.9928, -1.9929, -1.9930,  ..., -1.9891, -1.9891, -1.9891],\n",
       "           [-1.9928, -1.9929, -1.9930,  ..., -1.9893, -1.9893, -1.9893],\n",
       "           ...,\n",
       "           [-1.9952, -1.9947, -1.9941,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9952, -1.9947, -1.9941,  ..., -1.9915, -1.9915, -1.9915],\n",
       "           [-1.9952, -1.9947, -1.9941,  ..., -1.9907, -1.9907, -1.9907]],\n",
       " \n",
       "          [[-1.9928, -1.9928, -1.9929,  ..., -1.9890, -1.9890, -1.9890],\n",
       "           [-1.9928, -1.9928, -1.9929,  ..., -1.9891, -1.9891, -1.9891],\n",
       "           [-1.9928, -1.9928, -1.9929,  ..., -1.9893, -1.9893, -1.9893],\n",
       "           ...,\n",
       "           [-1.9953, -1.9943, -1.9931,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9953, -1.9943, -1.9931,  ..., -1.9915, -1.9915, -1.9915],\n",
       "           [-1.9953, -1.9943, -1.9931,  ..., -1.9907, -1.9907, -1.9907]],\n",
       " \n",
       "          [[-1.9928, -1.9928, -1.9929,  ..., -1.9890, -1.9890, -1.9890],\n",
       "           [-1.9928, -1.9928, -1.9929,  ..., -1.9891, -1.9891, -1.9891],\n",
       "           [-1.9928, -1.9928, -1.9929,  ..., -1.9893, -1.9893, -1.9893],\n",
       "           ...,\n",
       "           [-1.9953, -1.9943, -1.9931,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9953, -1.9943, -1.9931,  ..., -1.9915, -1.9915, -1.9915],\n",
       "           [-1.9953, -1.9943, -1.9931,  ..., -1.9907, -1.9907, -1.9907]]],\n",
       " \n",
       " \n",
       "         [[[-1.9930, -1.9934, -1.9940,  ..., -1.9897, -1.9898, -1.9900],\n",
       "           [-1.9932, -1.9936, -1.9940,  ..., -1.9903, -1.9905, -1.9905],\n",
       "           [-1.9934, -1.9937, -1.9940,  ..., -1.9909, -1.9910, -1.9911],\n",
       "           ...,\n",
       "           [-1.9954, -1.9954, -1.9954,  ..., -1.9948, -1.9949, -1.9948],\n",
       "           [-1.9957, -1.9958, -1.9959,  ..., -1.9946, -1.9948, -1.9947],\n",
       "           [-1.9960, -1.9961, -1.9962,  ..., -1.9944, -1.9946, -1.9945]],\n",
       " \n",
       "          [[-1.9930, -1.9934, -1.9940,  ..., -1.9897, -1.9898, -1.9900],\n",
       "           [-1.9932, -1.9936, -1.9940,  ..., -1.9903, -1.9905, -1.9905],\n",
       "           [-1.9934, -1.9937, -1.9940,  ..., -1.9909, -1.9910, -1.9911],\n",
       "           ...,\n",
       "           [-1.9954, -1.9954, -1.9954,  ..., -1.9948, -1.9949, -1.9948],\n",
       "           [-1.9957, -1.9958, -1.9959,  ..., -1.9946, -1.9948, -1.9947],\n",
       "           [-1.9960, -1.9961, -1.9962,  ..., -1.9944, -1.9946, -1.9945]],\n",
       " \n",
       "          [[-1.9931, -1.9934, -1.9938,  ..., -1.9900, -1.9900, -1.9901],\n",
       "           [-1.9933, -1.9935, -1.9938,  ..., -1.9905, -1.9905, -1.9906],\n",
       "           [-1.9934, -1.9934, -1.9938,  ..., -1.9909, -1.9910, -1.9912],\n",
       "           ...,\n",
       "           [-1.9957, -1.9956, -1.9956,  ..., -1.9871, -1.9873, -1.9874],\n",
       "           [-1.9960, -1.9960, -1.9961,  ..., -1.9868, -1.9869, -1.9870],\n",
       "           [-1.9961, -1.9962, -1.9963,  ..., -1.9866, -1.9866, -1.9866]],\n",
       " \n",
       "          ...,\n",
       " \n",
       "          [[-1.9937, -1.9938, -1.9939,  ..., -1.9908, -1.9908, -1.9908],\n",
       "           [-1.9937, -1.9938, -1.9939,  ..., -1.9909, -1.9909, -1.9909],\n",
       "           [-1.9937, -1.9938, -1.9939,  ..., -1.9910, -1.9910, -1.9910],\n",
       "           ...,\n",
       "           [-1.9954, -1.9949, -1.9943,  ..., -1.9935, -1.9935, -1.9935],\n",
       "           [-1.9954, -1.9949, -1.9943,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9954, -1.9949, -1.9943,  ..., -1.9917, -1.9917, -1.9917]],\n",
       " \n",
       "          [[-1.9936, -1.9937, -1.9938,  ..., -1.9908, -1.9908, -1.9908],\n",
       "           [-1.9936, -1.9937, -1.9938,  ..., -1.9909, -1.9909, -1.9909],\n",
       "           [-1.9936, -1.9937, -1.9938,  ..., -1.9910, -1.9910, -1.9910],\n",
       "           ...,\n",
       "           [-1.9956, -1.9947, -1.9934,  ..., -1.9935, -1.9935, -1.9935],\n",
       "           [-1.9956, -1.9947, -1.9934,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9956, -1.9947, -1.9934,  ..., -1.9917, -1.9917, -1.9917]],\n",
       " \n",
       "          [[-1.9936, -1.9937, -1.9938,  ..., -1.9908, -1.9908, -1.9908],\n",
       "           [-1.9936, -1.9937, -1.9938,  ..., -1.9909, -1.9909, -1.9909],\n",
       "           [-1.9936, -1.9937, -1.9938,  ..., -1.9910, -1.9910, -1.9910],\n",
       "           ...,\n",
       "           [-1.9956, -1.9947, -1.9934,  ..., -1.9935, -1.9935, -1.9935],\n",
       "           [-1.9956, -1.9947, -1.9934,  ..., -1.9925, -1.9925, -1.9925],\n",
       "           [-1.9956, -1.9947, -1.9934,  ..., -1.9917, -1.9917, -1.9917]]]])]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.__getitem__(\"tumblr_nkaeprvFbf1u680rpo1_400.gif\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unindent does not match any outer indentation level (<tokenize>, line 48)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<tokenize>\"\u001b[0;36m, line \u001b[0;32m48\u001b[0m\n\u001b[0;31m    test_data_path = os.path.join(self.dataframe_dir, 'Test_action_question.csv')\u001b[0m\n\u001b[0m    ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unindent does not match any outer indentation level\n"
     ]
    }
   ],
   "source": [
    "class TGIFDataset(Dataset):\n",
    "    def __init__(self, dataset_name='train', data_type=None, dataframe_dir=None, vocab_dir=None):\n",
    "        self.dataframe_dir = dataframe_dir # of the form data/tgif/vocabulary\n",
    "        self.vocab_dir = vocab_dir # of the form data/tgif/dataframe\n",
    "        self.data_type = data_type # 'TRANS'\n",
    "        self.dataset_name = dataset_name # 'train' or 'val' or 'test'\n",
    "\n",
    "        self.csv = self.read_from_csvfile()\n",
    "        self.header2idx = self.header2idx()\n",
    "        self.gif_names = self.csv[:,self.header2idx['gif_name']]\n",
    "        self.gif_tensor = None\n",
    "        self.questions = self.csv[:,self.header2idx['question']]\n",
    "        self.answers = self.csv[:,self.header2idx['answer']]\n",
    "        self.mc_options = self.csv[:,self.header2idx['a1']:header2idx['a5']+1]\n",
    "        ## GIF LOADER ##\n",
    "        ## NOTE: May have to change the relative path of gif dir as \n",
    "        ## an extra argument to TGIF class init\n",
    "        loader  = TGIF(cfg, \"train\")\n",
    "        self.get_gif_tensor = loader.__getitem__\n",
    "        \n",
    "    def __getitem__(self, i): # whats the argument for this\n",
    "    \tgif_path = os.path.join(self.dataframe_dir, 'gif_tensors')\n",
    "    \t#pick up ith gif_tensor\n",
    "        #NOTE: gif_path is only the gif name, not the relative path\n",
    "        # REturn value: tuple (slow frames, fast frames) where frame -> (t, 3, h, w)\n",
    "        gif_tensor = self.get_gif_tensor(gif_path)\n",
    "    \treturn self.gif_tensor, self.questions[i], self.mc_options[i], self.answers[i]\n",
    "\n",
    "    def header2idx(self):\n",
    "    \treturn {'gif_name':0,'question':1,'a1':2,'a2':3,'a3':4,'a4':5,'a5':6,'answer':7,'vid_id':8,'key':9}\n",
    "\n",
    "    def read_from_csvfile(self):\n",
    "        assert self.data_type in ['TRANS', 'ACTION'] # ACTION just for starting, will be using TRANS finally\n",
    "\n",
    "        self.total_q=[]\n",
    "        if self.data_type=='TRANS':\n",
    "            train_data_path = os.path.join(self.dataframe_dir, 'Train_transition_question.csv')\n",
    "            test_data_path = os.path.join(self.dataframe_dir, 'Test_transition_question.csv')\n",
    "\n",
    "            \n",
    "            with open(os.path.join(self.dataframe_dir, 'Total_transition_question.csv')) as file:\n",
    "            \tcsv_reader = csv.reader(file, delimiter='\\t')\n",
    "            \tfor row in csv_reader:\n",
    "            \t\tself.total_q.append(row)\n",
    "\n",
    "        elif self.data_type=='ACTION':\n",
    "         \ttrain_data_path = os.path.join(self.dataframe_dir, 'Train_action_question.csv')\n",
    "            test_data_path = os.path.join(self.dataframe_dir, 'Test_action_question.csv')\n",
    "\n",
    "            with open(os.path.join(self.dataframe_dir, 'Total_action_question.csv')) as file:\n",
    "            \tcsv_reader = csv.reader(file, delimiter='\\t')\n",
    "            \tfor row in csv_reader:\n",
    "            \t\tself.total_q.append(row)\n",
    "        \n",
    "        self.total_q.pop(0)\n",
    "\n",
    "        assert_exists(train_data_path)\n",
    "        assert_exits(test_data_path)\n",
    "\n",
    "        csv_data=[]\n",
    "        if self.dataset_name=='train':\n",
    "        \twith open(train_data_path) as file:\n",
    "        \t\tcsv_reader = csv.reader(file, delimiter='\\t')\n",
    "        \t\tfor row in csv_reader:\n",
    "        \t\t\tcsv_data.append(row)\n",
    "        elif self.dataset_name=='test':\n",
    "        \twith open(test_data_path) as file:\n",
    "        \t\tcsv_reader = csv.reader(file, delimiter='\\t')\n",
    "        \t\tfor row in csv_reader:\n",
    "        \t\t\tcsv_data.append(row)\n",
    "        csv_data.pop(0)\n",
    "\n",
    "        return np.asarray(csv_data)\n",
    "    '''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import csv\n",
    "import sys\n",
    "import numpy as np\n",
    "sys.path.insert(1, '../')\n",
    "from lxrt.SlowFast.slowfast.config.defaults import get_cfg\n",
    "from lxrt.SlowFast.slowfast.datasets.tgif_direct import TGIF\n",
    "\n",
    "\n",
    "cfg = get_cfg()\n",
    "cfg_file = \"../lxrt/SlowFast/configs/Kinetics/c2/SLOWFAST_8x8_R50.yaml\"\n",
    "cfg.merge_from_file(cfg_file)\n",
    "\n",
    "class FrameQADataset(object):\n",
    "    def __init__(self, dataset_name='train', data_type=None, dataframe_dir=None, vocab_dir=None, category =\"frameqa\" ):\n",
    "        self.dataframe_dir = dataframe_dir # of the form data/tgif/vocabulary\n",
    "        self.vocab_dir = vocab_dir # of the form data/tgif/dataframe\n",
    "        self.data_type = data_type # 'TRANS'\n",
    "        self.dataset_name = dataset_name # 'train' or 'val' or 'test'\n",
    "\n",
    "        self.csv, all_data = self.read_from_csvfile(category)\n",
    "        self.header2idx = self.header2idx()\n",
    "        self.gif_names = self.csv[:,self.header2idx['gif_name']]\n",
    "        self.gif_tensor = None\n",
    "        self.questions = self.csv[:,self.header2idx['question']]\n",
    "        self.answer = self.csv[:,self.header2idx['answer']]\n",
    "        self._build_ans_vocab(all_data[:,self.header2idx['answer']])\n",
    "        ## GIF LOADER ##\n",
    "        ## NOTE: May have to change the relative path of gif dir as \n",
    "        ## an extra argument to TGIF class init\n",
    "        root_path = \"/users/cdwivedi/RL_EXP/IDL/project/tgif-qa/code/dataset/tgif/frame_gifs/\"+dataset_name+\"/\"\n",
    "        loader  = TGIF(cfg, \"train\",root_path=root_path )\n",
    "        self.get_gif_tensor = loader.__getitem__\n",
    "        \n",
    "    def _build_ans_vocab(self, all_answers):\n",
    "        vocab = set()\n",
    "        for ans in all_answers:\n",
    "            vocab.add(str(ans))\n",
    "        self.vocab = sorted(list(vocab))\n",
    "        self.id2ans = self.vocab\n",
    "        self.ans2id = dict(zip(self.vocab, np.arange(len(self.vocab))))\n",
    "        self.vocab_len = len(self.vocab)\n",
    "        self.num_answers = self.vocab_len\n",
    "        self.label2ans = self.id2ans\n",
    "        \n",
    "    def __getitem__(self, i): # whats the argument for this\n",
    "        gif_path = self.gif_names[i]\n",
    "        #pick up ith gif_tensor\n",
    "        #NOTE: gif_path is only the gif name, not the relative path\n",
    "        # REturn value: tuple (slow frames, fast frames) where frame -> (t, 3, h, w)\n",
    "        gif_tensor = self.get_gif_tensor(gif_path)\n",
    "        \n",
    "        return gif_tensor, self.questions[i], self.ans2id[self.answer[i]]\n",
    "\n",
    "    def __len__(self):\n",
    "        return len(self.questions)\n",
    "    \n",
    "    def header2idx(self):\n",
    "        return {'gif_name':0,'question':1,'answer':2}\n",
    "\n",
    "    def read_from_csvfile(self, category=None):\n",
    "        print(category)\n",
    "        train_data_path = os.path.join(self.dataframe_dir, 'Train_'+category+'_question.csv')\n",
    "        test_data_path = os.path.join(self.dataframe_dir, 'Test_'+category+'_question.csv')\n",
    "        total_data_path = os.path.join(self.dataframe_dir, 'Total_'+category+'_question.csv')\n",
    "        csv_data=[]\n",
    "        if self.dataset_name=='train':\n",
    "            with open(train_data_path) as file:\n",
    "                csv_reader = csv.reader(file, delimiter='\\t')\n",
    "                for row in csv_reader:\n",
    "                    csv_data.append(row)\n",
    "        elif self.dataset_name=='test':\n",
    "            with open(test_data_path) as file:\n",
    "                csv_reader = csv.reader(file, delimiter='\\t')\n",
    "                for row in csv_reader:\n",
    "                    csv_data.append(row)\n",
    "        csv_data.pop(0)\n",
    "        total_csv_data=[]\n",
    "        with open(total_data_path) as file:\n",
    "            csv_reader = csv.reader(file, delimiter='\\t')\n",
    "            for row in csv_reader:\n",
    "                total_csv_data.append(row)\n",
    "\n",
    "        total_csv_data.pop(0)\n",
    "        return np.asarray(csv_data), np.asarray(total_csv_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_path= \"../../../../../../IDL/project/tgif-qa/dataset/\"\n",
    "file = \"Train_frameqa_question.csv\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "total_q =[]\n",
    "with open(data_path+file) as f:\n",
    "    reader = csv.reader(f, delimiter=\"\\t\")\n",
    "    for row in reader:\n",
    "        total_q.append(row)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "total_q = np.asarray(total_q)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "frameqa\n"
     ]
    }
   ],
   "source": [
    "d = FrameQADataset(dataframe_dir=\"../../../../../../IDL/project/tgif-qa/dataset/\", dataset_name=\"test\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1746"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.vocab_len"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/users/cdwivedi/RL_EXP/IDL/project/tgif-qa/code/dataset/tgif/frame_gifs/test/tumblr_no73q2fm0I1uuf348o1_250.gi/*\n",
      "torch.Size([3, 8, 256, 256]) torch.Size([3, 32, 256, 256])\n"
     ]
    }
   ],
   "source": [
    "for a in d:\n",
    "    break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([3, 32, 256, 256])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gif_tensor[1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
